package com.api.syh56.shengyunhui.controller;

import com.api.syh56.shengyunhui.common.BaseUserInfo;
import com.api.syh56.shengyunhui.common.CommonPage;
import com.api.syh56.shengyunhui.common.CommonResult;
import com.api.syh56.shengyunhui.common.UserInfoEnu;
import com.api.syh56.shengyunhui.entity.InvoiceTitle;
import com.api.syh56.shengyunhui.entity.InvoiceTitle;

import com.api.syh56.shengyunhui.service.InvoiceTitleService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 抬头
 */

@RestController
@RequestMapping("InvoiceTitle")
public class InvoiceTitleController {
    @Autowired
    private InvoiceTitleService invoiceTitleService;
    /**
     * 插入
     * @param invoiceTitle
     * @return
     */

    @PostMapping("insert")
    public CommonResult<Object> addNewAddress(@RequestBody InvoiceTitle invoiceTitle){
        invoiceTitleService.addNewInvoiceTitle(invoiceTitle);
        return CommonResult.success(invoiceTitle);
    }

    /**
     * 删除
     * @param invoiceTitle
     * @return
     */
    @PostMapping("delete")
    public CommonResult<Object> delete(@RequestBody InvoiceTitle invoiceTitle){
        invoiceTitleService.removeInvoiceTitle(invoiceTitle);
        return CommonResult.success(null);
    }

    /**
     * 更新
     * @param invoiceTitle
     * @return
     */
    @PostMapping("update")
    public CommonResult<Object> update(@RequestBody InvoiceTitle invoiceTitle){
        invoiceTitleService.updateInvoiceTitle(invoiceTitle);
        return CommonResult.success(null);
    }


    /**
     * 分页查询
     * @param pageSize
     * @param pageNum
     * @return
     */
    @RequestMapping (value = "selectPageByuid",method = RequestMethod.POST)
    public CommonResult<CommonPage<InvoiceTitle>>  selectPageByuid(@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        Long uid = Long.valueOf(BaseUserInfo.get(UserInfoEnu.id.getCode()));
        Page<InvoiceTitle> invoiceTitlePage = invoiceTitleService.selectPageByuid(uid, pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(invoiceTitlePage));
    }
}
